/**
   Project: primeval compiler
   File: VirtualMachine.h
   Authors: Sebastian Zanner Matr.Nr.: 0855172
   E-Mail: sebastian.zanner@stud.sbg.ac.at
*/

#ifndef VIRTUALMACHINE_H_INCLUDED
#define VIRTUALMACHINE_H_INCLUDED

// Format 1
#define TRAP 0

#define ADDI 1
#define SUBI 2
#define MULI 3
#define DIVI 4
#define MODI 5
#define CMPI 6

#define LDW  7
#define STW  8

#define POP  9
#define PSH  10

#define BEQ  11
#define BGE  12
#define BGT  13
#define BLE  14
#define BLT  15
#define BNE  16

#define BR   17
#define BSR  18

#define READI  19
#define PRINTI 20
#define READC 21
#define PRINTC 22
#define READB 23
#define PRINTB 24
#define PRINTS 25

// Format 2
#define ADD 26
#define SUB 27
#define MUL 28
#define Div 29
#define Mod 30
#define CMP 31
#define RET 32

// Format 3
#define JSR 33

#define TRUE 1
#define FALSE 0
#define MEMORYSIZE 32000
#define REGISTERSIZE 32

/*##############################################################################
#                                                                              #
# COMMANDS AND SPECIAL PURPOSE REGISTERS                                       #
#                                                                              #
##############################################################################*/
#define LINKREGISTER 31
#define STACKPOINTER 30
#define FRAMEPOINTER 29
#define GLOBALPOINTER 26


/*##############################################################################
#                                                                              #
# METHODS AND GLOBAL VARIABLES                                                 #
#                                                                              #
##############################################################################*/
int runVirtualMachine(int d, char *fileName);
void vm_usageError();
void vm_initialize();
int vm_readExecutableFileToMemory(char *fileName);
void vm_fetchInstruction();
int vm_decodeInstruction(char *op, char *a, char *b, int *c);
void vm_executeInstruction(char *op, char *a, char *b, int *c);
void vm_printStatus();
char *vm_getInstructionString(char op);

int vm_run;
int vm_debug;
long *vm_reg;
unsigned long vm_instructionRegister;
unsigned char *vm_memory;
int vm_programCounter;
long vm_programSize;

void printString(long address);

unsigned long temp;

#endif // VIRTUALMACHINE_H_INCLUDED

